<HTML><HEAD><TITLE>writeclause(+Stream, ?Clause)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>writeclause(+Stream, ?Clause)</H1>
The clause Clause is pretty printed on the output stream Stream .


<DL>
<DT><EM>Stream</EM></DT>
<DD>Integer (stream number) or Atom (reserved or user-defined                symbolic stream name).
</DD>
<DT><EM>Clause</EM></DT>
<DD>A Prolog term.
</DD>
</DL>
<H2>Description</H2>
   Used to pretty print the clause Clause on the output stream Stream
   according to the current operator declarations.

<P>
   When reading Prolog clauses from one file, and then writing to another,
   the latter part can be done using writeclause/2.  This is because the
   clauses are terminated by a period and a newline, which are not retained
   by prolog.  writeclause/2 replaces these, and flushes the output.

<P>
   writeclause/1,2 knows about the special meaning of ,/2, ;/2, -&gt;/2, fg
   --&gt;/2 and :-/2 and prints the clause with the appropriate indentation of
   subgoals and some (redundant) parantheses to show the clause structure.
   Everything else is written as with writeq/1,2, so output of writeclause/1,2
   is readable for read/1,2.
<P>

<H3>Modes and Determinism</H3><UL>
<LI>writeclause(+, ?) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Stream is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Stream is not an atom or an integer.
<DT><EM>(192) illegal stream mode </EM>
<DD>Stream is not an output stream.
<DT><EM>(193) illegal stream specification </EM>
<DD>Stream is an illegal stream specification.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      ?- writeclause(output, f(1,2,3)), writeclause(output, h(2,3)).
      f(1, 2, 3) .
      h(2, 3) .
      yes.

      ?- writeclause(output, X + 2).
      _56 + 2.
      yes.

      ?- writeclause(output, a(k):-write(k)).
      a(k) :-
              write(k) .
      yes.

      ?- writeclause(output, (a:-write(k),date(K))).
      a :-
              write(k),
              date(_68) .
      yes.

      ?- open(file1,update,s), writeclause(s, X + 2), close(s).
      X = _72
      yes.
      [eclipse]: sh('cat file1').
      _72 + 2.
      yes.

      ?- set_stream(a,output), writeclause(a, (:- dynamic f/1)).
      :- dynamic f / 1 .
      yes.

      ?- writeclause(output, (head:-a1,a2;a3,a4-&gt;a5;a6)).
      head :-
                (
                    a1,
                    a2
                ;
                    (
                        a3,
                        a4
                    -&gt;
                        a5
                    ;
                        a6
                    )
                ).
      yes.

Error:
      writeclause(S, a(b,c)).         (Error 4).
      writeclause("string" a(b,c)).   (Error 5).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/ioterm/writeq-2.html">writeq / 2</A>, <A HREF="../../kernel/ioterm/writeclause-1.html">writeclause / 1</A>
</BODY></HTML>
